package com.sanqi.work.util;

import java.util.Date;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

public class SQUserUtil {
    public static String getWorkUserTempLevel(Date hireDate) {
        DateTime thisDay = DateUtil.beginOfDay(DateUtil.date());
        //M2起始日期
        DateTime m2BeginDay = DateUtil.offsetMonth(hireDate, 1);
        DateTime m2OffsetMonth = DateUtil.offsetMonth(m2BeginDay, 1);
        //M2截止日期
        DateTime m2EndDay = DateUtil.endOfMonth(DateUtil.offsetDay(m2OffsetMonth, -1));
        //M3起始日期
        DateTime m3BeginDay = DateUtil.offsetDay(m2EndDay, 1);
        //M3截止日期
        DateTime m3EndDay = DateUtil.endOfMonth(m3BeginDay);
        //M4起始日期
        DateTime m4BeginDay = DateUtil.offsetDay(m3EndDay, 1);
        
        System.out.println(DateUtil.formatDate(hireDate));
        System.out.println("新会员有产当月:" + DateUtil.formatDate(hireDate) + "<->" + DateUtil.formatDate(DateUtil.offsetDay(m2BeginDay, -1)));
        System.out.println("新会员全月生产首月:" + DateUtil.formatDate(m2BeginDay) + "<->" + DateUtil.formatDate(m2EndDay));
        System.out.println("新会员全月生产第二个月:" + DateUtil.formatDate(m3BeginDay) + "<->" + DateUtil.formatDate(m3EndDay));
        System.out.println("认证会员（M4）:" + DateUtil.formatDate(m4BeginDay));
        if(m2BeginDay.compareTo(thisDay) > 0) {
            return "M1";
        }
        if(m2BeginDay.compareTo(thisDay) <= 0 && m2EndDay.compareTo(thisDay) >= 0) {
            return "M2";
        }
        if(m3BeginDay.compareTo(thisDay) <= 0 && m3EndDay.compareTo(thisDay) >= 0) {
            return "M3";
        }
        if(m4BeginDay.compareTo(thisDay) <= 0) {
            return "M4";
        }
        return null;
    }
    
    public static String getWorkUserTempLevel(Date hireDate, Date countDate) {
        DateTime thisDay = DateUtil.beginOfDay(countDate);
        //M2起始日期
        DateTime m2BeginDay = DateUtil.offsetMonth(hireDate, 1);
        DateTime m2OffsetMonth = DateUtil.offsetMonth(m2BeginDay, 1);
        //M2截止日期
        DateTime m2EndDay = DateUtil.endOfMonth(DateUtil.offsetDay(m2OffsetMonth, -1));
        //M3起始日期
        DateTime m3BeginDay = DateUtil.offsetDay(m2EndDay, 1);
        //M3截止日期
        DateTime m3EndDay = DateUtil.endOfMonth(m3BeginDay);
        //M4起始日期
        DateTime m4BeginDay = DateUtil.offsetDay(m3EndDay, 1);
        
        System.out.println(DateUtil.formatDate(hireDate));
        System.out.println("新会员有产当月:" + DateUtil.formatDate(hireDate) + "<->" + DateUtil.formatDate(DateUtil.offsetDay(m2BeginDay, -1)));
        System.out.println("新会员全月生产首月:" + DateUtil.formatDate(m2BeginDay) + "<->" + DateUtil.formatDate(m2EndDay));
        System.out.println("新会员全月生产第二个月:" + DateUtil.formatDate(m3BeginDay) + "<->" + DateUtil.formatDate(m3EndDay));
        System.out.println("认证会员（M4）:" + DateUtil.formatDate(m4BeginDay));
        if(m2BeginDay.compareTo(thisDay) > 0) {
            return "M1";
        }
        if(m2BeginDay.compareTo(thisDay) <= 0 && m2EndDay.compareTo(thisDay) >= 0) {
            return "M2";
        }
        if(m3BeginDay.compareTo(thisDay) <= 0 && m3EndDay.compareTo(thisDay) >= 0) {
            return "M3";
        }
        if(m4BeginDay.compareTo(thisDay) <= 0) {
            return "M4";
        }
        return null;
    }
}
